Pattern Matching
#WIP
古いものでは1937年のSASLにすでにあった
Some History of Functional Programming Languages
分配束縛と呼ぶ言語もある
destructuring bind
Clojureとか
代数的データ型のコンパイラの検査
網羅性
exhaustiveness
パターンに漏れがある場合はwarning
https://nymphium.github.io/2020/12/03/貧者の-Algebraic-Data-Types-と(浅い)網羅性判定.html
exhaustive check
非常調整
irredundancy
パターンに重複がある場合はwarning
上にあるものが優先される
いたる所のパターンマッチ
関数定義時
code:hs
eval (Add x y) = x + y
変数宣言時
code:hs
let (a, b, c) = (1, 2, 3)
パターンマッチの種類 ref 『n月刊ラムダノート Vol.1, No.3』.icon p.19
変数パターン
どんな値にでもマッチする
ワイルドカードパターン
タプルパターン
値の要素数違いは型検査器が行う
コンストラクタパターン
asパターン
https://gyazo.com/d97f95ec4ee7c44141acf6a503841d25
ネストした型のパターンも対応できる
code:ml
datatype stone = Black | White
datatype cell = Empty | Full of stone
fun isSequence s = case s of
(Full Black, Full Black, Full Black) => true
| (Full White, Full White, Full White) => true
| other => false
の実装解説記事
https://qiita.com/h_sakurai/items/04c242ea86810334cb1d
https://qiita.com/h_sakurai/items/cf24497279b5dd931e55
の言語比較
https://qiita.com/xmeta/items/91dfb24fa87c3a9f5993
https://qiita.com/cedretaber/items/64987eba457be806e335
https://qiita.com/vain0x/items/47bdd322d5de05c2db0b
Egisonとか
https://www.egison.org/ja/concept.html
/yubrot/Haskellから見るEgisonのパターンマッチング
HaskellのPattern Matchingはcaseの糖衣構文
http://www.sampou.org/haskell/report-revised-j/exps.html#sect3.17.3
関連
ECMAScript Pattern Matching
参考
『n月刊ラムダノート Vol.1, No.3』
↑の紹介された文献
https://www.microsoft.com/en-us/research/publication/the-implementation-of-functional-programming-languages/
http://pauillac.inria.fr/~maranget/papers/opat/
http://moscova.inria.fr/~maranget/papers/ml05e-maranget.pdf
https://www.jstage.jst.go.jp/article/jssst/24/2/24_2_2_113/_pdf
日本語
https://zenn.dev/blackenedgold/books/compiling-pattern-matching/viewer/pattern_matching_interpreter
CoPL 7章
https://propella.hatenablog.com/entry/20110222/p1
https://propella.hatenablog.com/entry/20101220/p1
https://elpinal.gitlab.io/publications/module_patterns.pdf
https://zenn.dev/blackenedgold/books/compiling-pattern-matching
https://github.com/SomewhatML/match-compile
https://keens.github.io/blog/2019/11/02/ngekkanramudano_tonipata_nmatchinitsuitekikoushimashita/
https://qiita.com/hinastory/items/87431aa48197cc4d7d84